package com.xbh.validator;

import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.validate.Validator;
import com.xbh.zzzTest.RetTest;

/**
 * <p>
 *
 * </p>
 *
 * @author: ZBoHang
 * @time: 2021/8/2 16:33
 */
public class MyValidator extends Validator {

    @Override
    protected void validate(Controller controller) {
        setRet(RetTest.me.fail());
        //设置短路
        this.setShortCircuit(true);
        String name = controller.getPara("name");
        if("name".equals(name)) {
            addError("name", "nameMsg");
        }
        String pass = controller.getPara("pass");
        if("pass".equals(pass)) {
            addError("pass", "passMsg");
        }
    }

    @Override
    protected void handleError(Controller controller) {

       // 可keepPara 可render("error.html")
        controller.renderJson(getRet());
    }
}
